<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>jewOrderEdit</title>
     <%@ include file="../common/static.html" %>
    <style type="text/css">
    	.l-toolbar { height: 32px;}
    </style>
  </head>
  <body>
  	<div id="top_menu" ></div>
  	<div id="detailform"></div>
  	<div id="detailtabs" style="margin:5px;">
  		<div title="产品明细">
  			<div id="tabitem1"></div>
  		</div>
  		<div title="其余副石">
  			<div id="tabitem2"></div>
  		</div>
  		<div title="来金">
  			<div id="tabitem3"></div>
  		</div>
  		<div title="来石">
  			<div id="tabitem4"></div>
  		</div>
  		<div title="来配件">
  			<div id="tabitem5"></div>
  		</div>
  	</div>
  	<div id="bottom_menu" ></div>
	<script type="text/javascript">
	(function($){
			var JewOrderEdit={
					consData:function(){
						var id=$.getParam("id"),tabid=this.getTabId(),grid=this.getGrid();
						if(id){
							var test={
									tabitem1:{"jeworderid": id,"jewtype":"123","status":"待分款","unitno":"1","styleno":"AAA"},
									tabitem2:{},
									tabitem3:{},
									tabitem4:{},
									tabitem5:{}
							};
							//TODO 测试数据
							var testData={Rows:	[]};
							var consSize=parseInt(Math.random()*10);
							for(var i=0;i<consSize;i++){
								var tmpData={};
								$.extend(true,tmpData,test[tabid])
								testData.Rows.push(tmpData);
							}
							if(grid)
								grid.loadData(testData);
						}
					},
					copyData:function(copySize){
						var copyedData=null,selected=this.getSelected(),grid=window.grid=this.getGrid(),addedData={Rows:[]};//{Rows:grid.getData()};
						while(copySize-->0){
							if(!copyedData){
								copyedData={};
								$.each(selected,function(i,v){
									if(i.indexOf("_")==-1){
										copyedData[i]=v;
									}
								});
							}
							var tmpData={};
							$.extend(true,tmpData,copyedData);
							addedData.Rows.push(tmpData);
						}
						//grid.loadData(addedData);
						grid.addRows(addedData.Rows);
					},
					loadMenu:function(){
						var event=function(item){
							if(item.id=="back"){
								document.location.href="./jewOrderList.jsp";
							}else{
								console.log("TODO save");
							}
						};
						var option={
								items: [
										{ text: "返回", icon:"back",id:"back",click: event},
										{ line:true },
								        {text: "保存", icon:"save",id:"save",click: event}
                              	]
						};
						$("#top_menu,#bottom_menu").ligerToolBar(option);
					},
					loadForm:function(){
						//testData
						var testData1=[{text:"选项1",id:"1"},{text:"选项2",id:"2"},{text:"选项3",id:"3"},{text:"选项4",id:"4"},{text:"选项5",id:"5"}];
						var testData2=[{text:"选项1",id:"1"},{text:"选项2",id:"2"},{text:"选项3",id:"3"},{text:"选项4",id:"4"},{text:"选项5",id:"5"}];
						var testData3=[{text:"选项1",id:"1"},{text:"选项2",id:"2"},{text:"选项3",id:"3"},{text:"选项4",id:"4"},{text:"选项5",id:"5"}];
						var testData4=[{text:"选项1",id:"1"},{text:"选项2",id:"2"},{text:"选项3",id:"3"},{text:"选项4",id:"4"},{text:"选项5",id:"5"}];
						
						$("#detailform").ligerForm({
			                inputWidth: 130, labelWidth: 80, space: 30,
			                fields: [
			                        { group: "基础信息"},
					                { display: "订单号", name: "order_id", type: "text",newline: false},
					                { display: "制单人 ", name: "order_pp", type: "text",newline: false},
					                { display: "制单时间 ", name: "order_time", type: "text",newline: false},
					                { display: "状态", name: "order_status", type: "text",newline: false},
					                { display: "客户", name: "custom_name", type: "select",newline: true,options:{data:testData1,textField:"text",valueField:"id"}},
					                { display: "总件数", name: "custom_count", type: "text",newline: false},
					                { display: "产品类别", name: "categroy", type: "select" ,newline: false,options:{data:testData2,textField:"text",valueField:"id"}},
					                { display: "金属成色", name: "metal", type: "select" ,newline: false,options:{data:testData3,textField:"text",valueField:"id"}},
					                { display: "字印", name: "text", type: "text" ,newline: true },
					                { display: "金价", name: "price", type: "number" ,newline: false },
					                { display: "预付金额", name: "pre_pay", type: "text" ,newline: false },
					                { display: "出货日期", name: "out_time", type: "date" ,newline: false },
					                { display: "接单人", name: "rec_pp", type: "select" ,newline: true,options:{data:testData4,textField:"text",valueField:"id"}},
					                { display: "备注", name: "remark", type: "text" ,width:610,newline: false }
			                ],
			                onAfterSetFields:function(){
			                	liger.get("detailform").setData({
			                		order_id:$.getParam("id"),
			                		order_pp:"weizs",
			                		order_time:"2013-06-13 22:20:10",
			                		order_status:"待打印"
			                	});
			                	liger.get("order_id").setDisabled();
			                	liger.get("order_pp").setDisabled();
			                	liger.get("order_time").setDisabled();
			                	liger.get("order_status").setDisabled();
			                }
			            }); 
					},
					loadDetail:function(){
						var c=this;
						var event=function(item){
							var itemId=item?item.id:null;
							if(itemId=="add"){
								c.getGrid().addEditRow();
							}else if (itemId=="save"){
								//TODO
							}else{
								var selected=c.getSelected();
								if(selected){
									switch(itemId){
										case "copy":
											$.ligerDialog.prompt('请输入复制件数', '1', function (yes, value){
												if (yes) c.copyData(parseInt(value));
								            });
											break;
										case "delete":
											//c.copyData(c.getTabId(),1);
											break;
										case "select":
											//c.copyData(c.getTabId(),1);
											break;
										default:
											return;
									}
								}
							}
						};
						var defaultOptions={
									isScroll : true,
									checkbox : true,
									rownumbers : true,
									enabledEdit: true,
									clickToEdit:true,
									//height:400,
									toolbar:{
										items : [
										          {	text :"增加",	icon : "add" , id:"add",click :event}, 
										          {line : true}, 
										          {text : "复制",icon : "plus",id:"copy",click : event}, 
										          {line : true},
										          {text : "删除",icon : "delete",id:"delete",click : event},
										          {line : true},
										          {text : "选款",icon : "attibutes",id:"select",click : event}, 
										          {line : true},
										          {text : "保存",icon : "save",id:"save",click : event}
										]
									}
						};
						var gridOptions={
								tabitem1:$.extend(true,{
									data:{Rows:[]},
									columns : [
											{display : '主键',name : 'id',hide:true},
											{display : '订单编号',name : 'jeworderid',editor: { type: 'text'}},
											{display : '状态',name : 'status',editor: { type: 'text'}},
											{display : '款号',name : 'styleno',editor: { type: 'text'}},
											{display : '首饰类别',	name : 'jewtype',editor: { type: 'text' }},
											{display : '件数',	name : 'unitno',editor: { type: 'text' }},
											{display : '手寸',	name : 'handinch',editor: { type: 'text' }},
											{display : '来主石',	name : 'ismstone',editor: { type: 'text' }},
											{display : '主石号',	name : 'mstoneid',editor: { type: 'text' }},
											{display : '主石名',	name : 'mstonename',editor: { type: 'text' }},
											{display : '主石规格',	name : 'mstonespec',editor: { type: 'text' }},
											{display : 'mstoneweight',	name : 'mstoneweight',editor: { type: 'text' }},
											{display : 'mstoneno',	name : 'mstoneno',editor: { type: 'text' }},
											{display : 'needstoneno',	name : 'needstoneno',editor: { type: 'text' }},
											{display : 'unit',	name : 'unit',editor: { type: 'text' }}
									]
								},defaultOptions),
								tabitem2:$.extend(true,{
									data:{Rows:[]},
									columns : [
											{display : '主键',name : 'id',	hide:true},
											{display : '订单编号',name : 'jeworderid'},
											{display : 'isvstone',name : 'isvstone',editor: { type: 'text' }},
											{display : 'vstoneid',name : 'vstoneid',editor: { type: 'text' }},
											{display : 'vstonename',name : 'vstonename',editor: { type: 'text' }},
											{display : 'vstonespec',name : 'vstonespec',editor: { type: 'text' }},
											{display : 'vstoneweight',name : 'vstoneweight',editor: { type: 'text' }},
											{display : 'vstoneno',name : 'vstoneno',editor: { type: 'text' }},
											{display : 'needvstone',name : 'needvstone',editor: { type: 'text' }},
											{display : 'unit',name : 'unit',editor: { type: 'text' }},
											{display : 'vstoneprice',name : 'vstoneprice',editor: { type: 'text' }},
											{display : 'vstonelathe',name : 'vstonelathe',editor: { type: 'text' }},
											{display : 'vstoneshape',name : 'vstoneshape',editor: { type: 'text' }}
									]
								},defaultOptions),
								tabitem3:$.extend(true,{
									data:{Rows:[]},
									columns : [
											{display : '主键',name : 'id',	hide:true},
											{display : '订单编号',name : 'jeworderid'},
											{display : 'quality',name : 'quality',editor: { type: 'text' }},
											{display : 'weight',name : 'weight',editor: { type: 'text' }},
											{display : 'disrate',name : 'disrate',editor: { type: 'text' }},
											{display : '单价',name : 'unitprice',editor: { type: 'text' }},
											{display : '备注',name : 'note',editor: { type: 'text'}},
											{display : '收单人',name : 'receiverid',editor: { type: 'text' }},
											{display : '接收时间',name : 'receivetime',type : 'date',format: 'yyyy年MM月dd日'}
									]
								},defaultOptions),
								tabitem4:$.extend(true,{
									data:{Rows:[]},
									columns : [
											{display : '主键',name : 'id',	hide:true},
											{display : '订单编号',name : 'jeworderid'},
											{display : 'stoneid',name : 'stoneid',editor: { type: 'text' }},
											{display : 'stonename',name : 'stonename',editor: { type: 'text' }},
											{display : 'stoneweight',name : 'stoneweight',editor: { type: 'text' }},
											{display : 'stoneno',name : 'stoneno',editor: { type: 'text' }},
											{display : '收单人',name : 'receiverid',editor: { type: 'text' }},
											{display : '备注',name : 'note',editor: { type: 'text' }},
											{display : '接收时间',name : 'receivetime',type : 'date',format: 'yyyy年MM月dd日'}
									]
								},defaultOptions),
								tabitem5:$.extend(true,{
									data:{Rows:[]},
									columns : [
											{display : '主键',name : 'id',	hide:true},
											{display : '订单编号',name : 'jeworderid'},
											{display : 'accsid',name : 'accsid',editor: { type: 'text' }},
											{display : 'accsname',name : 'accsname',editor: { type: 'text' }},
											{display : 'accsweight',name : 'accsweight',editor: { type: 'text' }},
											{display : 'accsno',name : 'accsno',editor: { type: 'text' }},
											{display : '收单人',name : 'receiverid',editor: { type: 'text' }},
											{display : '备注',name : 'note',editor: { type: 'text' }},
											{display : '接收时间',name : 'receivetime',type : 'date',format: 'yyyy年MM月dd日'}
									]
								},defaultOptions)
						};
						var option={
								changeHeightOnResize:true,
								onAfterSelectTabItem:function(tabid){
									if(!c[tabid])
										c[tabid]=$("#"+tabid).ligerGrid(gridOptions[tabid]);
									//c[tabid].reload();
									c.currentTabItemId=tabid;
								}
						};
						$("#detailtabs").ligerTab(option);
						//默认第一页
						c["tabitem1"]=$("#tabitem1").ligerGrid(gridOptions["tabitem1"]);
						c.currentTabItemId="tabitem1";
						c.consData();
					},
					getSelected :function(){
						var tabid=this.getTabId();
						if(tabid){
							var selected = this[tabid]?this[tabid].getSelected():null;
							if (!selected) {
								LG.tip('请选择行!');
							}else{
								return selected;
							}
						}
						return false;
					},
					getTabId:function(){
						var tabid=this.currentTabItemId;
						return tabid;
					},
					getGrid:function(){
						return this[this.getTabId()];
					},
					render:function(){
						this.loadMenu();
						this.loadForm();
						this.loadDetail();
					}
			};
			$(document).ready(function(){
				JewOrderEdit.render();
			});
	})(jQuery);
	</script>
  </body>
</html>
